package com.yusong.test.collection;

import java.util.Arrays;

/**
 * Created by yusong on 2017/3/15.
 * Arrays.copyOf 浅拷贝
 * System.arraycopy 未知
 *  Collections.copy(a,c);深拷贝
 */
public class SystemArrayCopy {

    public static void main(String[] args) {
        StringBuilder[] a =  new StringBuilder[3];
        a[0] = new StringBuilder("aaa");
        a[1] = new StringBuilder("bbb");
        a[2] = new StringBuilder("ccc");
        //浅拷贝
        StringBuilder[] b = Arrays.copyOf(a,2);
        StringBuilder[] c = new StringBuilder[3];
       // System.arraycopy(a,0,c,2,2);


        System.out.println(a[1]);
        System.out.println(b.length);
        //不相等
        System.out.println(a == b);

        //两个对象都改变了
        b[1].append("ddd");
        System.out.println(a[1]);
        System.out.println(b[1]);

        System.out.println(c[1]);
    }
}
